package com.leetcode.merci.lc74;

/**
 * Created by bowen on 2017/7/27.
 */
public class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        if (matrix == null || matrix.length == 0) {
            return false;
        }
        int m=matrix.length;
        int n=m==0?1:matrix[0].length;
        int l=0;
        int r=m*n-1;
        int mid;
        while(l!=r){
            mid=l+r-1>>1;
            if(matrix[mid/n][mid%n]<target){
                l=mid+1;
            }
            else{
                r=mid;
            }
        }
        return target==matrix[r/n][r%n];
    }
    public static void main(String[] args) {
        int[][] t={};
        Solution solution=new Solution();
        solution.searchMatrix(t,2);

    }
}